package com.useeinfo.oa.modules.maintaining.entity;

import com.alibaba.fastjson.JSONObject;
import com.useeinfo.framework.extend.entity.SuperClassEntity;
import com.useeinfo.framework.sugar.tools.StringConverters;
import com.useeinfo.oa.modules.base.entity.Enterprise;
import com.useeinfo.oa.modules.base.entity.FacilityCat;
import com.useeinfo.oa.modules.base.entity.Organization;

import javax.persistence.*;

/**
 * 维保工艺表
 */
@Entity
@Table(name = "maintain_technology")
public class MaintainTechnology extends SuperClassEntity<MaintainTechnology> {
    /**
     * 流水号
     */
    private String code;
    /**
     * 保养名称
     */
    private String name;
    /**
     * 所属类型
     */
    @ManyToOne
    @JoinColumn(name = "facilityCat_Id")
    private FacilityCat facilityCat;
    /**
     * 所属部门
     */
    @ManyToOne
    @JoinColumn(name = "organization_id")
    private Organization organization;
    /**
     * 施工准备工作
     */
    @Column(columnDefinition="text")
    private String prepareWork;
    /**
     * 预计工时(分钟)
     */
    private String estimateTime;
    /**
     * 要求技能
     */
    private String requireSkill;
    /**
     * 是否有效
     */
    @Column(columnDefinition = "bit default 0")
    private Boolean effective;
    /**
     * 安全要求
     */
    private String safetyRequirement;
    /**
     * 所需材料
     */
    private String requireMaterials;
    /**
     * 所需工具
     */
    private String requireTools;
    /**
     * 详细说明
     */
    @Column(columnDefinition="text")
    private String description;
    /**
     * 维保内容快照
     *  {
     * 	"updateDate": "2019-01-03 10:13:14",
     * 	"applicationScenariosName": "场景2",    --应用场景名
     * 	"applicationScenariosId": 2,            --应用场景ID
     * 	"inputTypeEnumText": "数字",            --输入类型名
     * 	"name": "111",                          --维保项目
     * 	"id": 1,
     * 	"category": "中度保养",                  --维保类别（轻度保养 中度保养 深度保养）
     * 	"createDate": "2019-01-02 16:51:40",
     * 	"inputTypeEnumCode": "NUMBER"           --输入类型CODE
     * }
     */
    @Column(columnDefinition="text")
    private String maintainDataContent;

    /**
     * 所属企业
     */
    @ManyToOne
    @JoinColumn(name = "enterprise_id")
    private Enterprise enterprise;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public FacilityCat getFacilityCat() {
        return facilityCat;
    }

    public void setFacilityCat(FacilityCat facilityCat) {
        this.facilityCat = facilityCat;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public String getPrepareWork() {
        return prepareWork;
    }

    public void setPrepareWork(String prepareWork) {
        this.prepareWork = prepareWork;
    }

    public String getEstimateTime() {
        return estimateTime;
    }

    public void setEstimateTime(String estimateTime) {
        this.estimateTime = estimateTime;
    }

    public String getRequireSkill() {
        return requireSkill;
    }

    public void setRequireSkill(String requireSkill) {
        this.requireSkill = requireSkill;
    }

    public Boolean getEffective() {
        return effective;
    }

    public void setEffective(Boolean effective) {
        this.effective = effective;
    }

    public String getSafetyRequirement() {
        return safetyRequirement;
    }

    public void setSafetyRequirement(String safetyRequirement) {
        this.safetyRequirement = safetyRequirement;
    }

    public String getRequireMaterials() {
        return requireMaterials;
    }

    public void setRequireMaterials(String requireMaterials) {
        this.requireMaterials = requireMaterials;
    }

    public String getRequireTools() {
        return requireTools;
    }

    public void setRequireTools(String requireTools) {
        this.requireTools = requireTools;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public String getMaintainDataContent() {
        return maintainDataContent;
    }

    public void setMaintainDataContent(String maintainDataContent) {
        this.maintainDataContent = maintainDataContent;
    }

    @Override
    public JSONObject toJSONObject() {
        JSONObject jsonObject = super.toJSONObject();
        jsonObject.put("name", StringConverters.null2String(getName()));
        jsonObject.put("code", StringConverters.null2String(getCode()));
        jsonObject.put("prepareWork", StringConverters.null2String(getPrepareWork()));
        jsonObject.put("estimateTime", StringConverters.null2String(getEstimateTime()));
        jsonObject.put("requireSkill", StringConverters.null2String(getRequireSkill()));
        jsonObject.put("effective", StringConverters.null2Boolean(getEffective()));
        if(getFacilityCat()!=null){
            jsonObject.put("facilityCatName", StringConverters.null2String(getFacilityCat().getCatName()));
            jsonObject.put("facilityCatId", getFacilityCat().getId());
        }else{
            jsonObject.put("facilityCatName", "");
            jsonObject.put("facilityCatId", "");
        }

        if(getEnterprise()!=null){
            jsonObject.put("enterpriseName", StringConverters.null2String(getEnterprise().getEnterpriseName()));
        }else{
            jsonObject.put("enterpriseName", "");
        }
        if(getOrganization()!=null){
            jsonObject.put("organizationName", StringConverters.null2String(getOrganization().getOrganizationName()));
        }else{
            jsonObject.put("organizationName", "");
        }
        return jsonObject;
    }
}
